import Vue from 'vue'
import Vuex from 'vuex'
import { apiGetInfo } from '@/api/login'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    userInfo: '',
    baseUrl: 'http://localhost:1337'
  },
  mutations: {
    // 设置userInfo
    setUserInfo (state, payload) {
      state.userInfo = payload
    }
  },
  actions: {
    async setUserInfo (content) {
      // console.log(111)
      const res = await apiGetInfo()
      // console.log(222)
      res.data.avatar = `http://localhost:1337${res.data.avatar}`
      content.commit('setUserInfo', res.data)
    }
  },
  modules: {}
})
